/*
	File:		main.cpp
	Author:		dmonroe
	Date:		10/14/2012
	Copyright:	Full Sail University

	Purpose:	Test the OpenGL wrapper
*/

#include <assert.h>

// Memory leak detection?
#if (defined( _DEBUG ) || defined( DEBUG )) && (defined( _WIN32 ) || defined( WIN32 ))
#include <vld.h>
#endif // (defined( _DEBUG ) || defined( DEBUG )) && (defined( _WIN32 ) || defined( WIN32 ))


#include "../source/Constants.h"
#include "../source/Game.h"
#include "../source/ExitCodes.h"




//******************************************************************
// MAIN
int main( int argc, char** argv )
{
	// Ignore params
	(void)argc;
	(void)argv;

	
	////////////////////////////////////////////////////////////////
	// INITIALIZATION
	CGame* pGame = CGame::GetInstance();

	if( pGame->Initialize() == false )
	{
		// MESSAGE
		assert( false && "main - Game could not be initialized" != 0 );
		return MAIN_EXIT_INIT_FAILURE;
	}
	////////////////////////////////////////////////////////////////

	
	
	////////////////////////////////////////////////////////////////
	// GAME LOOP
	int exitCode = MAIN_EXIT_SUCCESS;
	do
		exitCode = pGame->Update();
	while( exitCode == MAIN_CONTINUE );
	////////////////////////////////////////////////////////////////


	
	////////////////////////////////////////////////////////////////
	// TERMINATION
	pGame->Terminate();
	pGame->DeleteInstance();
	pGame = NULL;
	////////////////////////////////////////////////////////////////


	return exitCode;
}
//******************************************************************



/*		// TESTING

#include <cassert>

#include "../source/Constants.h"
#include "../source/IGraphics.h"
#include "../source/Geometry.h"

#if defined( _DEBUG ) || defined( DEBUG )
#if defined( _WIN32 ) || defined( WIN32 )

#include <Windows.h>
#include <vld.h>

#endif // defined( _WIN32 ) || defined( WIN32 )
#endif // defined( _DEBUG ) || defined( DEBUG )

#if defined( _WIN32 ) || defined( WIN32 )
#define		IMAGE_SHIP	"resources/graphics/SapperShip.dds"
#else
#define		IMAGE_SHIP	"/app_home/resources/graphics/SapperShip.gtf"
#endif


int main( int argc, char** argv )
{
	// Ignore params
	(void)argc;
	(void)argv;

	
	////////////////////////////////////////////////////////////////
	// INITIALIZATION
	IGraphics* pGraphics = IGraphics::GetInstance();
	unsigned short width  = 640;
	unsigned short height = 480;
	bool result = pGraphics->Initialize( "Hello World", width, height );

	assert( result != false && "main - Graphics could not be initialized" );
	if( result == false )
		return 0x1;
	
	////////////////////////////////////////////////////////////////


	HTexture image	= pGraphics->LoadTexture( IMAGE_SHIP );
	HTexture image2 = pGraphics->LoadTexture( IMAGE_SHIP );
	pGraphics->UnloadTexture( image2 );
	
	SRect region = { 0, 32, 64, 128 };
	SPoint ptPos = { };
	SPoint ptVel = { 1, 1 };



	////////////////////////////////////////////////////////////////
	// GAME LOOP
	while( true )
	{
		
		// Escape to quit?
#if defined( _WIN32 ) || defined( WIN32 )
		if( (GetAsyncKeyState( VK_ESCAPE ) & 0x8000) == 0x8000 )
			break;
#endif // defined( _WIN32 ) || defined( WIN32 )




		if( pGraphics->Update() == false )
			break;


		pGraphics->BeginScene();
		
		// draw stuff
		pGraphics->DrawTexture( image, 0, 0 );
		//pGraphics->DrawTextureSection( image, 0, 0, &region, 0.0f, 0.0f, 0.0f, SColor( 255, 100, 100, 255 ) );
		pGraphics->DrawRectangle( &region, 0.0f, 0.0f, 0.0f, SColor( 0, 0, 255, 128 ) );

		pGraphics->DrawLine( 200, 100, 300, 300, SColor( 255, 255, 255, 50 ), 2.0f, false );

	

		// BOUNCING BOX 
		ptPos.x += ptVel.x;
		ptPos.y += ptVel.y;

		if( ptPos.x < 0 )
		{
			ptPos.x = 0;
			ptVel.x = -ptVel.x;
		}
		else if( ptPos.x + 50 > width )
		{
			ptPos.x = width - 50;
			ptVel.x = -ptVel.x;		
		}
	
		if( ptPos.y < 0 )
		{
			ptPos.y = 0;
			ptVel.y = -ptVel.y;
		}
		else if( ptPos.y + 100 > height )
		{
			ptPos.y = height - 100;
			ptVel.y = -ptVel.y;		
		}

		SRect box = { ptPos.x, ptPos.y, ptPos.x + 50, ptPos.y + 100 };
		pGraphics->DrawRectangle( &box );


		pGraphics->EndScene();
	}
	////////////////////////////////////////////////////////////////

	pGraphics->UnloadTexture( image );
	
	////////////////////////////////////////////////////////////////
	// TERMINATION
	pGraphics->Terminate();
	pGraphics = NULL;
	IGraphics::DeleteInstance();
	////////////////////////////////////////////////////////////////


	return 0;
}
*/
